/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

private ["_helo","_cRoF","_cFireRate","_array","_weaponclass","_mRoF","_mFireRate","_pilot","_aimingQuality"];

/* sets variables */
_array = _this select 3;
_helo = _array select 0;
_weaponclass = _array select 1;
_mRoF = 2.5;
_mFireRate = 1;
_pilot = driver _helo;
_grp = group _pilot;

/* forces the server side helo object to become client side. */
[_helo] joinSilent player;
[_helo] joinSilent grpNull;
[_helo] joinSilent _grp;
_helo setBehaviour "SAFE";
_helo setCombatMode "BLUE";

/* checks the amount of ammo available and displays it */
if (_helo ammo _weaponclass <= 6) then {
	_pilot sidechat format["Down to %1 missiles left!",_helo ammo _weaponclass];
} else {
	if (0 == _helo ammo _weaponclass) exitWith {
		_pilot sidechat "Winchester";
	};
};

/* checks to make sure that the laser designator is active before firing */
if (isNull (laserTarget player)) exitWith {
	_pilot sideChat "Not able to Shoot, laser target lost";
	_cFireRate = 0;
};

/* checks the aiming value */
_aimingQuality = gunner _helo AimedAtTarget [(laserTarget player),"missiles_DAGR"];

/* checks distance to target */
if (_helo distance (laserTarget player) < 2000) then {
	/* verifies the hit chance */
	// if (_aimingQuality > 0.3) then {
		/* loop for single to multi missile fire support */
		waitUntil{
			sleep _mRoF;
			_helo setVectorUp [.20,0,1];
			_helo fireAtTarget [(laserTarget player),_weaponclass];
			_mFireRate = _mFireRate - 1;
			/* ends the wait loop when value reached */
			_pilot sidechat "Beam Rider!";
			_mFireRate <= 0;
		};
	// } else {
		// _pilot sidechat "Aborting ATGM Mission, target outside gimble limits";
	// };
} else {
	_pilot sidechat "Aborting ATGM Mission, target out of range.";
};

/* exits script when done */
if (true) exitWith {};